package combinationPattern;

import java.awt.*;

public class BaseShape implements Shape{
    public int x;
    public int y;
    public Color color;
    public boolean selected = false;

    public BaseShape(int x, int y, Color color) {
        this.x = x;
        this.y = y;
        this.color = color;
    }

    @Override
    public int getX() {
        return x;
    }

    @Override
    public int getY() {
        return y;
    }

    @Override
    public int getWidth() {
        return 0;
    }

    @Override
    public int getHight() {
        return 0;
    }

    @Override
    public void move(int x, int y) {
        this.x+=x;
        this.y+=y;
    }

    @Override
    public boolean isInsideBounds(int x, int y) {
        return x>getX()&&x<(getX()+getWidth())&&y<getY()&&y<(getY()+getHight());
    }

    @Override
    public void select() {
        selected=true;
    }

    @Override
    public void unSelect() {
        selected=false;
    }

    @Override
    public boolean isSelected() {
        return selected;
    }

    public void enableSelectionStyle(java.awt.Graphics graphics){
        graphics.setColor(Color.LIGHT_GRAY);
        Graphics2D g2= (Graphics2D) graphics;
        float[] dash1={2.0f};
        g2.setStroke(new BasicStroke(1.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,2.0f,dash1,0.0f));
    }
    public void disableSelectionStyle(java.awt.Graphics graphics){
        graphics.setColor(color);
        Graphics2D g2=(Graphics2D) graphics;
        g2.setStroke(new BasicStroke());
    }
    @Override
    public void paint(Graphics graphics) {
        if (isSelected()){
            enableSelectionStyle(graphics);
        }
        else{
            disableSelectionStyle(graphics);
        }
    }

}
